package cn.jhc.servlet;
import java.io.File; 
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.jhc.dao.ConnectionFactory;

@WebServlet("/houtaideleteyuepu.do")
public class Houtai_DeleteYuepuServlet extends HttpServlet {
	@Override
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		Connection conn = null;
		PreparedStatement pstmt = null;

		String strId = request.getParameter("id");
		if (null == strId || strId.equals(""))
        {
            return;
        }
 

		 int id=Integer.parseInt(strId);
		try
        {
            conn = ConnectionFactory.getConnection();
            pstmt = conn.prepareStatement(
                "delete from uploadfile where id=?");
            pstmt.setInt(1,id);
            pstmt.executeUpdate();
        }
		catch (SQLException e) {
			System.err.println(e);
		}
		if(pstmt!=null)
        {
            try
            {
                pstmt.close();
            }
            catch(SQLException e)
            {
                System.err.println(e);
            }
            pstmt=null;
        }
        if(conn!=null)
        {
            try
            {
                conn.close();
            }
            catch(SQLException e)
            {
                System.err.println(e);
            }
            conn=null;
        }
		RequestDispatcher dispatcher = request
				.getRequestDispatcher("/houtai_deleteyuepu.jsp");
		dispatcher.forward(request, response);

	}

	@Override
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}
	
}
